var fileSystemObject = new ActiveXObject("Scripting.FileSystemObject");
var adoStream;
//将临时文件上传至服务器
function uploadPhotoImg(imagePath){
	var basePath=$("#basePath").val();
	var firstGuid=$("#firstGuid").val();		
	adoStream = new ActiveXObject("ADODB.Stream");
	adoStream.Mode = 3;//read write
			
	adoStream.Open();
	adoStream.Type = 1;
	//文件类型
	var fileType = imagePath.substring(imagePath.lastIndexOf(".")+1);
	//上传url
	var upOneURL = basePath+"/upload/uploadLocalImg";
	adohttp = getXMLHttpRequest();
	//访问方式
	adohttp.open('post', upOneURL, false);
	//文件类型
	adohttp.setRequestHeader('-fileType',fileType);
	adohttp.setRequestHeader('-firstGuid',firstGuid);//Scan.MrId
			
			
	adohttp.setRequestHeader('-pageOneLocalPath',imagePath.replace(/\\/g,"/"));
	adohttp.setRequestHeader('Content-Type', 'application/x- www-form-urlencoded');

	//获取本地文件   	
	adoStream.LoadFromFile(imagePath);
			
	//获取文件大小
	var fileSize = fileSystemObject.GetFile(imagePath).Size;
	var adoStreamSize = adoStream.Size;
			
	if (fileSize != adoStreamSize || fileSize < 3584 || adoStreamSize < 3584){
		adoStream.Close();////
		adoStream = null;
		adohttp = null;
		return "noUp";
	}
			
	adohttp.setRequestHeader("Content-Length",adoStream.Size);
			
	adohttp.send(adoStream.Read(adoStream.Size));
	//返回数据
	var result = JSON.parse(adohttp.responseText);
		   
	//关闭流   	
	adoStream.Close();////
	adoStream = null;
		   	
	adohttp = null;
		   	
	return result;
}

//获取XmlHttpRequest
function getXMLHttpRequest(){
	var XMLHttpRequest = null;
	if (typeof ActiveXObject != "undefined") {
		var aVersions = ["Microsoft.XMLHTTP", "Msxml2.XMLHttp.6.0", "Msxml2.XMLHttp.5.0", "Msxml2.XMLHttp.4.0", "Msxml2.XMLHttp.3.0"];
		for (var i = 0; i < aVersions.length; i++) {
			try {XMLHttpRequest = new ActiveXObject(aVersions[i]);}catch (ex) {}//注释：不能alert循环的创建的
		}
	} else if (typeof XMLHttpRequest != "undefined"){
		XMLHttpRequest = new XMLHttpRequest();
	}
			
		return XMLHttpRequest;
}





//拍摄图片
function photoImg(){
	$("#picDiv").html("");
	//删除临时文件夹
	CAPTURE.deletePhotoImg();
	//初始化默认信息
	CAPTURE.init();
	//拍摄图片返回文件名
	var fileName = CAPTURE.photoJPSImg();
	//var picHostPath="http://localhost:8090/upload/temp/";
	
	var filePath=CAPTURE.tempPath+fileName+".jpg";
	
	alert(filePath);
	
	var result= uploadPhotoImg(filePath);
	if(result.ret=="success"){
		var hostFileName=result.fileName;
		var picHostPath=$("#picHostPath").val();
		var fileUrl=picHostPath+"tempImgPath/"+hostFileName;
		var html="<img width='270' id='img' fileName='"+hostFileName+"' height='320' src='"+fileUrl+"'/>";
		$("#picDiv").html(html);
	}
	
	
}

	/*$('#Edit').on("click", function() {
		easyDialog.open({
			container : 'div_TC',
			fixed : true,
		});
		//开启摄像头
		//CAPTURE.openMainCaptrue();
		$('#closeBtn2').on("click", function() {
			
			var firstGuid=$("#firstGuid").val();
			//关闭摄像头
			//CAPTURE.closeCaptrue();
			easyDialog.close();
			//window.location.href="${basePath}/scan/photoPicPage?firstGuid="+firstGuid;
			
		});
	})
*/
	//删除拍摄图片
	function deleteImg(){
		$("#picDiv").html("");
		//删除临时文件夹图片信息
		CAPTURE.deletePhotoImg();
		
	}
	
		
		